package hu.fic.weddingstorefinder.listadapter;


import hu.fic.weddingstorefinder.R;
import hu.fic.weddingstorefinder.parcel.DressParcelable;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


public class DressListAdapter extends BaseAdapter {
	ArrayList<ListItem> listItems;
	
	public DressListAdapter(ArrayList<ListItem> listItems) {
		this.listItems = listItems;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listItems.size();
	}

	@Override
	public Object getItem(int position) {
		return listItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View viewToReturn = convertView;

		final ListItem listItem = listItems.get(position);
		LayoutInflater inflater = (LayoutInflater) parent.getContext()
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (listItem != null) {
			if(listItem.isSection()){
				DressListSectionHeader sectionHeader = (DressListSectionHeader)listItem;
				viewToReturn = inflater.inflate(R.layout.dresslist_sectionheader_row, null);

				viewToReturn.setOnClickListener(null);
				viewToReturn.setOnLongClickListener(null);
				viewToReturn.setLongClickable(false);
				
				TextView sectionView = (TextView) viewToReturn.findViewById(R.id.dresslist_sectionheader_textview);
				sectionView.setText(sectionHeader.getSectionTitle());
			}else{
				DressParcelable dress = (DressParcelable)listItem;
				viewToReturn = inflater.inflate(R.layout.dresslist_content_row, null);
				TextView title = (TextView)viewToReturn.findViewById(R.id.dresslist_content_dressdesc);
				title.setText(dress.getDressDesc());
				
			}
		}
		return viewToReturn;
	}

}
